package ThreadMethod;

public class Method01 {
    public static void main(String[] args) throws InterruptedException {
        MyThread myThread = new MyThread();
        myThread.start();
        //通知完myThread后,main后休眠2秒
        Thread.sleep(2000);
        for (int i = 0; i <10 ; i++) {
            System.out.println(Thread.currentThread().getName()+"-"+i);
        }
        MyRunnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable);
    thread.start();
    }
}
//线程类
class MyThread extends  Thread{
    @Override
    public void run() {
        for (int i = 0; i <10 ; i++) {
            //获得当前线程的线程名称
            System.out.println(Thread.currentThread().getName()+"-"+i);
        }
    }
}
class  MyRunnable implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i <20 ; i++) {
            if (i %2==0) {
                System.out.println("线程2除以偶数休眠2秒");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+i);
            }
        }
    }
}
